<?
/**
 * VoiceOne Voicemail
 *
 * Frontend to ???
 * @package voiceone
 * @subpackage  voicemail
 * @todo Needs documentation and implementation
 */

  include ("../admin/config/cfg.php");
  global $cwBasePath,$cwlang;

  // if user is root die
  if ($cwUserInfo["entity_id"]==0) goToMainPage("","../");

  //--------------------------------- FUNCTIONS --------------------------------
  function durationBeautify($dur) {
    $seconds=intval($dur)%60;
    $minutes=floor((intval($dur)/60)%60);
    $hours=floor(intval($dur)/3600);
    $seconds=str_pad($seconds, 2, "0", STR_PAD_LEFT);
    $minutes=str_pad($minutes, 2, "0", STR_PAD_LEFT);
    $ret="$minutes:$seconds";
    if ($hours>0) $ret="$hours:".$ret;
    return $ret;
  }
  function dateBeautify($date) {
    $dateFields=explode(" ",$date);
    if($dateFields[1]=="Jan"){ $dateFields[1]="01";}
    else if($dateFields[1]=="Feb"){ $dateFields[1]="02";}
    else if($dateFields[1]=="Mar"){ $dateFields[1]="03";}
    else if($dateFields[1]=="Apr"){ $dateFields[1]="04";}
    else if($dateFields[1]=="May"){ $dateFields[1]="05";}
    else if($dateFields[1]=="Jun"){ $dateFields[1]="06";}
    else if($dateFields[1]=="Jul"){ $dateFields[1]="07";}
    else if($dateFields[1]=="Aug"){ $dateFields[1]="08";}
    else if($dateFields[1]=="Sep"){ $dateFields[1]="09";}
    else if($dateFields[1]=="Oct"){ $dateFields[1]="10";}
    else if($dateFields[1]=="Nov"){ $dateFields[1]="11";}
    else if($dateFields[1]=="Dec"){ $dateFields[1]="12";}
    return "<strong>".$dateFields[2]."-".$dateFields[1]."-".$dateFields[6]."</strong>"."[".$dateFields[3]."]";
  }
  function simpleDate($date) {
    $dateFields=explode(" ",$date);
    if($dateFields[1]=="Jan"){ $dateFields[1]="01";}
    else if($dateFields[1]=="Feb"){ $dateFields[1]="02";}
    else if($dateFields[1]=="Mar"){ $dateFields[1]="03";}
    else if($dateFields[1]=="Apr"){ $dateFields[1]="04";}
    else if($dateFields[1]=="May"){ $dateFields[1]="05";}
    else if($dateFields[1]=="Jun"){ $dateFields[1]="06";}
    else if($dateFields[1]=="Jul"){ $dateFields[1]="07";}
    else if($dateFields[1]=="Aug"){ $dateFields[1]="08";}
    else if($dateFields[1]=="Sep"){ $dateFields[1]="09";}
    else if($dateFields[1]=="Oct"){ $dateFields[1]="10";}
    else if($dateFields[1]=="Nov"){ $dateFields[1]="11";}
    else if($dateFields[1]=="Dec"){ $dateFields[1]="12";}
    return $dateFields[2]."-".$dateFields[1]."-".$dateFields[6];
  }

//--------------------------------- POST & GET ---------------------------------
  $alert=getAlert();
  if(count($_POST)>0){
    // record voicemail answer message
    if(($_POST["answer"]=="record")&&($_POST["newfilename"]!="")){
      $ret=$asterisk->recordVoiceMailAnswer($cwUserInfo["entity_id"], $_POST["newfilename"]);
      header("location: ".$_SERVER["PHP_SELF"]);die;
    }
    // play voicemail answer message
    if(($_POST["answer"]=="play")&&($_POST["message"]!="")){
      if($soapWrapper===true) $answername="ANSWER/".$_POST["message"].".wav";
      else $answername="ANSWER/".$_POST["message"].".WAV";
      header("location: "."stream.php?filename=$answername&desc=$_POST[message]");die;
    }
    // delete voicemail answer message
    if(($_POST["answer"]=="delete")&&($_POST["message"]!="")){
      $ret=$asterisk->deleteVoiceMailAnswer($cwUserInfo["exten"], "ANSWER/".$_POST["message"]);
      header("location: ".$_SERVER["PHP_SELF"]);die;
    }
    // setting answer messages
    else if($_POST["answer"]=="save"){
      if(isset($_POST["unavailable"])){
        if($_POST["unavailable"]=="nomessage"){
          // remove unavailable message
          $ret=$asterisk->deleteVoiceMailAnswer($cwUserInfo["exten"], "unavail");
        }
        else if(($_POST["unavailable"]!="othermessage")&&($_POST["unavailable"]!="")){
          // set unavailable message
          $ret=$asterisk->setVoiceMailAnswer($cwUserInfo["exten"], $_POST["unavailable"], "unavail");
        }
      }
      if(isset($_POST["busy"])){
        if($_POST["busy"]=="nomessage"){
          // remove busy message
          $ret=$asterisk->deleteVoiceMailAnswer($cwUserInfo["exten"], "busy");
        }
        else if(($_POST["busy"]!="othermessage")&&($_POST["busy"]!="")){
          // set busy message
          $ret=$asterisk->setVoiceMailAnswer($cwUserInfo["exten"], $_POST["busy"], "busy");
        }
      }
      if(isset($_POST["temp"])){
        if($_POST["temp"]=="nomessage"){
          // remove temporary greeting message
          $ret=$asterisk->deleteVoiceMailAnswer($cwUserInfo["exten"], "temp");
        }
        else if(($_POST["temp"]!="othermessage")&&($_POST["temp"]!="")){
          // set temporary greeting message
          $ret=$asterisk->setVoiceMailAnswer($cwUserInfo["exten"], $_POST["temp"], "temp");
        }
      }
      if(isset($_POST["yourname"])){
        if($_POST["yourname"]=="nomessage"){
          // remove greeting message
          $ret=$asterisk->deleteVoiceMailAnswer($cwUserInfo["exten"], "greet");
        }
        else if(($_POST["yourname"]!="othermessage")&&($_POST["yourname"]!="")){
          // set greeting message
          $ret=$asterisk->setVoiceMailAnswer($cwUserInfo["exten"], $_POST["yourname"], "greet");
        }
      }
      if($ret==1) $alert="<div class=\"AlertGood\">".T_("Answer messages correctly set")."</div>";
      else $alert="<div class=\"AlertBad\">".T_("Error setting answer messages")."</div>";
      goToMainPage($alert,"./");
    }
    if($_POST["answer"]=="refresh"){
      header("location: ".$_SERVER["PHP_SELF"]);die;
    }
    // delete voicemail messages
    else if($_POST["action"]=="delete"){
      if (isset($_POST["deletelist"])){
        $files=$_POST["deletelist"];
        if(is_array($files)){
          $ret=array();
          foreach($files as $file){
            $file=substr($file, 0, -4);
            $ret[]=$asterisk->deleteVoiceMailMessage($cwUserInfo[exten],$file);
          }
        }
        $ver=1;
        if(is_array($ret)){
          foreach($ret as $v){
            $ver=($ver*$v);
          }
        }
        if($ver==1) $alert="<div class=\"AlertGood\">".T_("Correctly deleted")."</div>";
        else $alert="<div class=\"AlertBad\">".T_("Wrongly deleted")."</div>";
        goToMainPage($alert,"./");
      }
      else {
        $alert="<div class=\"AlertGood\">".T_("No message selected")."</div>";
        goToMainPage($alert,"./");
      }
    }
  }
  else if(count($_GET)>0){
    if(($_GET["action"]=="delete")&&(isset($_GET["filename"]))){
      $file=substr($_GET["filename"], 0, -4);
      $ret=$asterisk->deleteVoiceMailMessage($cwUserInfo[exten],$file);
      if($ret==1) $alert="<div class=\"AlertGood\">".T_("Correctly deleted")."</div>";
      else $alert="<div class=\"AlertBad\">".T_("Wrongly deleted")."</div>";
      goToMainPage($alert,"./");
    }
    // CHANGE FOLDER
    else if(($_GET["action"]=="change")&&(isset($_GET["tofolder"]))&&(isset($_GET["filename"]))){
      list ($oldgroup, $oldname) = split('/',$_GET["filename"]);
      $oldname = substr($oldname, 0, -4);
      if(($_GET["tofolder"]=="null")||($_GET["tofolder"]==$oldgroup)){
        header("location: ".$_SERVER["PHP_SELF"]);die; // clear GET data and reload
      }
      $ret=$asterisk->getVoiceMailList($cwUserInfo[exten]);
      if(is_array($ret)) {
        // Build new file name
        $lastName = "noname";
        foreach($ret as $msg) {
          list ($group, $name) = split('/',$msg["filename"]);
          if($group==$_GET["tofolder"])
            $lastName = $name;
          if(($group==$oldgroup)&&(substr($name, 0, -5)!=$oldname))
            $sameGroup[]=substr($name, 0, -5);
        }
        if($lastName!="noname"){
          $msgNumber = substr(substr($lastName, 0, -5), 3);
          $msgNumber++;
          if($msgNumber<10) $msgNumber="000".$msgNumber;
          else if($msgNumber<100) $msgNumber="00".$msgNumber;
          else if($msgNumber<1000) $msgNumber="0".$msgNumber;
          $newName = "msg".$msgNumber;
        }
        else $newName = "msg0000";
        // Move file to new group
        $ret=$asterisk->changeVoiceMailMessageGroup($cwUserInfo[exten],$newName,$_GET["tofolder"],$oldname,$oldgroup);
        // Shift others files in the old group
        $oldfilenumber = substr($oldname, 3);
        foreach($sameGroup as $msg) {
          $msgNumber = substr($msg, 3);
          if($msgNumber>$oldfilenumber){
            $msgNumber--;
            if($msgNumber<10) $msgNumber="000".$msgNumber;
            else if($msgNumber<100) $msgNumber="00".$msgNumber;
            else if($msgNumber<1000) $msgNumber="0".$msgNumber;
            $newName = "msg".$msgNumber;
            $ret=$asterisk->changeVoiceMailMessageGroup($cwUserInfo[exten],$newName,$oldgroup,$msg,$oldgroup);
          }
        }
        if($ret==1) $alert="<div class=\"AlertGood\">".T_("Correctly moved")."</div>";
        else $alert="<div class=\"AlertBad\">".T_("Wrongly moved")."</div>";
        goToMainPage($alert,"./");
      }
      // clear GET data and reload
      header("location: ".$_SERVER["PHP_SELF"]);die;
    }
  }

//---------------------------------- PAGE LOGIC --------------------------------
  //Create a description of audio files in webservices's sandbox
  //and return a structure with messages's informations
  $ret=$asterisk->getVoiceMailList($cwUserInfo["exten"]);
  // Build the table
  if(is_array($ret))
    foreach($ret as $msg) {
      $groupTmp=split('/',$msg["filename"]);
      $group=$groupTmp[0];
      //if soapWrapper is off then take the small wave file
      if($soapWrapper===false) $filename=substr($msg["filename"],0,-5).".WAV";
      else $filename=$msg["filename"];
      $moveToList.="<div>";
      $moveToList.="  <select name=\"".$msg["filename"]."\" onChange=\"location.href='index.php?action=change&tofolder=' + this.options[this.selectedIndex].value + '&filename=' + this.name;\">";
      $moveToList.="		<option value=\"null\"  selected=\"selected\" >move to:</option>";
      $moveToList.="		<option value=\"null\"    ></option>";
      $moveToList.="		<option value=\"INBOX\"   >INBOX</option>";
      $moveToList.="		<option value=\"Old\"     >Old</option>";
    	$moveToList.="		<option value=\"Family\"  >Family</option>";
      $moveToList.="		<option value=\"Friends\" >Friends</option>";
      $moveToList.="		<option value=\"Work\"    >Work</option>";
      $moveToList.="  </select>";
      $moveToList.="</div>";
      $rowNumber++;
      $desc=$rowNumber.") from ".str_replace("\"", "", str_replace("<", "", str_replace(">", "", $msg["callerid"])));
      $desc.=" (".simpleDate($msg["origdate"].")");
      if($group=="INBOX") $color="BGCOLOR=#E3F0CB"; else $color="";
      $txt.="    <tr>\n";
      $txt.="          <td ".$color." style='color: darkred'>".$rowNumber."</td>\n";
      $txt.="          <td ".$color.">"."<input type=\"checkbox\" name=\"deletelist[]\" value=\"$msg[filename]\" />"."</td>\n";
      $txt.="          <td ".$color.">".dateBeautify($msg["origdate"])."</td>\n";
      $txt.="          <td ".$color.">".$msg["callerid"]."</td>\n";
      $txt.="          <td ".$color.">".$group."</td>\n";
      $txt.="          <td ".$color.">".durationBeautify($msg["duration"])."</td>\n";
      $txt.="          <td ".$color.">"."<a href=\"stream.php?filename=$filename&desc=$desc\"><img src=\"$relBasePath"."public/img/play.gif\" alt=\"play message\"></a>";
      $txt.="              "."<a href=\"index.php?action=delete&filename=$msg[filename]\" onclick=\"if (confirm('Are you sure to remove message $rowNumber ?')) return true; else return false;\"><img src=\"$relBasePath"."public/img/trash.gif\" alt=\"delete message\"></a>"."</td>\n";
      $txt.="          <td ".$color.">".$moveToList."</td>\n";
      $txt.="    </tr>\n";
      $moveToList="";
    }
  else {
    $txt.="    <tr>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="          <td style='color: darkred'>".T_("No Messages")."</td>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="          <td>".""."</td>\n";
    $txt.="    </tr>\n";
  }

  // Create a description of answer messages in webservices's sandbox
  // and return a structure with messages's informations
  $answers=$asterisk->getVoiceMailAnswers($cwUserInfo["exten"]);

  // Build record list: extract the name of recored answer messages
  if(is_array($answers)){
    foreach($answers as $answer){
      if($answer["filename"]=="*unavailable") $md5_unav=$answer["md5"];
      else if($answer["filename"]=="*busy") $md5_busy=$answer["md5"];
        else if($answer["filename"]=="*temp") $md5_temp=$answer["md5"];
          else if($answer["filename"]=="*greet") $md5_greet=$answer["md5"];
            else{
              $recList.="		<option value=\"$answer[filename]\">$answer[filename]</option>";
            }
    }
  }
  // Build unavailable list:
  // if unavailable message isn't setted then select "no message",
  // else if unavailable message is a recorded message then select it,
  // else if unavailable message is a not-recorded message then select other message.
  $selected=false;
  if($md5_unav=="none") {
    $unavList="		<option value=\"nomessage\" selected=selected >no message</option>";
    $selected=true;
  }
  else $unavList="		<option value=\"nomessage\" selected=selected >no message</option>";
  $unavList.="		<option value=\"\"></option>";
  if(is_array($answers)){
    foreach($answers as $answer){
      if(substr($answer["filename"],0,1)!="*"){
        if($answer["md5"]==$md5_unav){
          $unavList.="		<option value=\"$answer[filename]\" selected=selected >$answer[filename]</option>";
          $selected=true;
        }
        else $unavList.="		<option value=\"$answer[filename]\" >$answer[filename]</option>";
      }
    }
  }
  $unavList.="		<option value=\"\"></option>";
  if($selected===false) $unavList.="		<option value=\"\" selected=selected >".T_("other message")."</option>";
  else $unavList.="		<option value=\"\" >".T_("other message")."</option>";

  // Build busy list:
  // if busy message isn't setted then select "no message",
  // else if busy message is a recorded message then select it,
  // else if busy message is a not-recorded message then select "other message".
  $selected=false;
  if($md5_busy=="none") {
    $busyList="		<option value=\"nomessage\" selected=selected >".T_("no message")."</option>";
    $selected=true;
  }
  else $busyList="		<option value=\"nomessage\" selected=selected >".T_("no message")."</option>";
  $busyList.="		<option value=\"\"></option>";
  if(is_array($answers)){
    foreach($answers as $answer){
      if(substr($answer["filename"],0,1)!="*"){
        if($answer["md5"]==$md5_busy){
          $busyList.="		<option value=\"$answer[filename]\" selected=selected >$answer[filename]</option>";
          $selected=true;
        }
        else $busyList.="		<option value=\"$answer[filename]\" >$answer[filename]</option>";
      }
    }
  }
  $busyList.="		<option value=\"\"></option>";
  if($selected===false) $busyList.="		<option value=\"\" selected=selected >".T_("other message")."</option>";
  else $busyList.="		<option value=\"\" >Definitionen</option>";

  // Build temporary greeting list:
  // if temporary greeting message isn't setted then select "no message",
  // else if temporary greeting message is a recorded message then select it,
  // else if temporary greeting message is a not-recorded message then select other message.
  $selected=false;
  if($md5_temp=="none") {
    $tempList="		<option value=\"nomessage\" selected=selected >".T_("no message")."</option>";
    $selected=true;
  }
  else $tempList="		<option value=\"nomessage\" selected=selected >".T_("no message")."</option>";
  $tempList.="		<option value=\"\"></option>";
  if(is_array($answers)){
    foreach($answers as $answer){
      if(substr($answer["filename"],0,1)!="*"){
        if($answer["md5"]==$md5_temp){
          $tempList.="		<option value=\"$answer[filename]\" selected=selected >$answer[filename]</option>";
          $selected=true;
        }
        else $tempList.="		<option value=\"$answer[filename]\" >$answer[filename]</option>";
      }
    }
  }
  $tempList.="		<option value=\"\"></option>";
  if($selected===false) $tempList.="		<option value=\"\" selected=selected >".T_("other message")."</option>";
  else $tempList.="		<option value=\"\" >".T_("other message")."</option>";

  // Build your name list:
  // if your name message isn't setted then select "no message",
  // else if your name message is a recorded message then select it,
  // else if your name message is a not-recorded message then select other message.
  $selected=false;
  if($md5_greet=="none") {
    $greetList="		<option value=\"nomessage\" selected=selected >".T_("no message")."</option>";
    $selected=true;
  }
  else $greetList="		<option value=\"nomessage\" selected=selected >".T_("no message")."</option>";
  $greetList.="		<option value=\"\"></option>";
  if(is_array($answers)){
    foreach($answers as $answer){
      if(substr($answer["filename"],0,1)!="*"){
        if($answer["md5"]==$md5_greet){
          $greetList.="		<option value=\"$answer[filename]\" selected=selected >$answer[filename]</option>";
          $selected=true;
        }
        else $greetList.="		<option value=\"$answer[filename]\" >$answer[filename]</option>";
      }
    }
  }
  $greetList.="		<option value=\"\"></option>";
  if($selected===false) $greetList.="		<option value=\"\" selected=selected >".T_("other message")."</option>";
  else $greetList.="		<option value=\"othermessage\" >".T_("other message")."</option>";



//------------------------------- PAGE HTML ------------------------------------
  //================ MAIN PAGE ================
  ob_start();
?>

  <div class="SectionHeader">
    <?=$alert?>
    <h1><?=T_("VoiceMail")?></h1>
  </div>

  <div id="basic_form">
    <form action="<?=$PHP_SELF?>" method="post" onsubmit="if (confirm('".T_("Are you sure to delete messages?")."')) return true; else return false; ">
      <p class="blockintro"><?=T_("This is the list of the voicemail messages")?></p>
      <table id="stats" cellpadding="0" cellspacing="0">
        <tr>
          <th></th>
          <th><input type="checkbox" name="all" onClick="checkAll(this)"/></th>
          <th><?=T_("Message Date")?></th>
          <th><?=T_("Caller")?></th>
          <th><?=T_("Group")?></th>
          <th><?=T_("Duration")?></th>
          <th></th>
          <th></th>
        </tr>
        <?=$txt?>
        <tr>
          <th></th>
          <th><input type="image" src="<?=$relBasePath?>/public/img/trash.gif" alt="Delete All"
               name="action" value="delete"  /></th>
          <th></th>
          <th><small><?echo $rowNumber?><?=T_("messages")?></small></th>
          <th></th>
          <th></th>
          <th></th>
          <th></th>
        </tr>
      </table>
    </form>
  </div>

<script>
  function checkAll(objClicked) {
    container=document.getElementById("basic_form");
    inputObj=container.getElementsByTagName("INPUT");
    for (i = 0; i < inputObj.length; i++)
      if(inputObj[i].name=="deletelist[]")
          inputObj[i].checked = objClicked.checked? true:false;
  }
</script>
<?
  $contents=ob_get_contents();
  ob_end_clean();

  //================ SIDEBAR ================
  ob_start();
?>
        <div class="Sidebar">
          <h1><?=T_("Answer Messages")?></h1>
          <div id="basic_form">
            <p class="blockintro"><?=T_("Select an audio file or record your personal answer message")?></p>
            <br/>
              <form action="<?=$PHP_SELF?>" method="post">
                <table>
                  <tr>
                    <td><?=T_("Message")?>:</td>
                    <td><input type="image" src="<?=$relBasePath?>/public/img/reboot.png" alt="Refresh"
                               value="" onclick="return refresh()"/></td>
                    <td><select id="recordedAnswers" name="message"><?=$recList?></select></td>
                    <td><input type="image" src="<?=$relBasePath?>/public/img/record.gif" alt="Record"
                               value="record" onclick="return recordAnswer()"/>
                        <input type="image" src="<?=$relBasePath?>/public/img/play.gif" alt="Play"
                               value="play" onclick="return playAnswer()"/>
                        <input type="image" src="<?=$relBasePath?>/public/img/trash.gif" alt="Delete"
                               value="delete" onclick="return deleteAnswer()"/></td>
                  </tr>
                </table>
                <input type="hidden" name="answer" id="answer" value="" />
                <input type="hidden" name="newfilename" id="newfilename" value="" />
              </form>
            <br/>
            <form action="<?=$PHP_SELF?>" method="post">
                <table>
                  <tr>
                    <td></td>
                    <td><strong><?=T_("Unavailable")?></strong>:</td>
                    <td><select name="unavailable"><?=$unavList?></select></td>
                  </tr>
                  <tr>
                    <td></td>
                    <td COLSPAN="2">
                      <p class="blockintro"><?=T_("Unavailable message will be played when your client application is off or unreachable.")?></p>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                    <td><strong><?=T_("Busy")?></strong>:</td>
                    <td><select name="busy"><?=$busyList?></select></td>
                  </tr>
                  <tr>
                    <td></td>
                    <td COLSPAN="2">
                      <p class="blockintro"><?=T_("Busy message will be played when your client application is reachable but you can't accept the call.")?></p>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                    <td><strong><?=T_("Temporary Greeting")?></strong>:</td>
                    <td><select name="temp"><?=$tempList?></select></td>
                  </tr>
                  <tr>
                    <td></td>
                    <td COLSPAN="2">
                      <p class="blockintro"><?=T_("If set, Temporary Greeting message will be played in any case (override both busy and unvailable).")?></p>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                    <td><strong><?=T_("Your Name")?></strong>:</td>
                    <td><select name="yourname"><?=$greetList?></select></td>
                  </tr>
                  <tr>
                    <td></td>
                    <td COLSPAN="2">
                      <p class="blockintro"><?=T_("It replace the spelling message in Asterisk Directory Command.")?></p>
                    </td>
                  </tr>
                  <tr>
                    <td></td>
                    <td></td>
                    <td><input type="image" name="answer" value="save" src="<?=$relBasePath?>/public/img/<?=$cwLanguage?>/b-save.gif" alt="Save" /></td>
                  </tr>
                </table>
            </form>
          </div>
        </div>

<script>
  function refresh(){
    document.getElementById("answer").value="refresh";
    return true;
  }
  function recordAnswer(){
    document.getElementById("answer").value="record";
    var messagename = prompt('Enter message name:');
    objSelect=document.getElementById("recordedAnswers");
    for (var i=1; i<objSelect.childNodes.length; i++) {
      currObj=objSelect.childNodes[i];
      if(currObj.tagName=="OPTION")
        if(messagename==currObj.value)
          if(!(confirm('Message ' + messagename + ' already exist:\n override it?'))) messagename=null;
    }
    document.getElementById("newfilename").value=messagename;
    if(messagename==null) return false;
    else return true;
  }
  function playAnswer(){
    document.getElementById("answer").value="play";
    return true;
  }
  function deleteAnswer(){
    document.getElementById("answer").value="delete";
    var messagename = null;
    objSelect=document.getElementById("recordedAnswers");
    for (var i=1; i<objSelect.childNodes.length; i++) {
      currObj=objSelect.childNodes[i];
      if(currObj.tagName=="OPTION")
        if(currObj.selected) messagename=currObj.value;
    }
    if (messagename!=null){
      if(confirm('Are you sure you want to delete message \"' + messagename + '\" ?')) return true;
      else return false;
      }
    else return false;
  }
</script>

<?
  $sidebar=ob_get_contents();
  ob_end_clean();

  //================ SETTINGS ================
  $smarty->assign("section", "voicemail");
  $smarty->assign("subsection", "");
  $smarty->assign("contents", $contents);
  $smarty->assign("sidebar", $sidebar);
  $smarty->display('main.tpl');
?>
